
#ifndef POLYGONITEM_H
#define POLYGONITEM_H

#include <BMap>
#include <BPair>
#include <BPointArray>
#include <BPolygon2Array>
#include <BGraphicItem>

using namespace BWE;

class PolygonItem : public BGraphicItem
{
	BOBJECT(PolygonItem);
public:
	PolygonItem(BGraphicItem* parent = 0);
	~PolygonItem();

	void appendPoint(const BPointf& point);
	void insertPoint(int index, const BPointf& point);
	void removePoint(int index);
	void clearPoints();

	const BPointfArray& points() const;

	void clearPolygons();
	int splitPolygons();

protected:
	virtual void paint(BPainter& painter);

	virtual void freshEvent(const BEvent& event);

	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);

	virtual void mouseClickEvent(const BMouseEvent& mouseEvent);

private:
	BArray<BPointf>		_originPoints;
	mutable bool			_dirty;
	mutable BPointfArray	_points;
	mutable BPolygon2fArray	_polygons;
	BMap<float, BPair<int, BPointf>> _crossPoints;
};

#endif
